home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / emacs_src_18_58.lha / emacs-18.58 / lisp / keypad.el < prev    next >
Lisp/Scheme  |  1992-02-21  |  6KB  |  153 lines

  1. ;; Terminal-independent keypad and function key bindings.
  2. ;; Copyright (C) 1986 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 1, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  
  21. ;; These keys are handled by a two-level process.
  22. ;; The first level, terminal-dependent, maps input sequences
  23. ;; into the function keys that they represent.
  24. ;; The second level, terminal-independent but customized by users,
  25. ;; map function keys into meanings.
  26.  
  27. ;; This file takes care of the second level of mapping.
  28. ;; The first, terminal-dependent, level is handled by the
  29. ;; terminal-specific files term/*.el.
  30.  
  31. ;; The second-level mapping is done by a keymap, function-keymap.
  32. ;; Here we document the meanings of the "characters" defined by
  33. ;; function-keymap.
  34.  
  35. ;; What do these letters mean?
  36. ;; When we say that ``a stands for the clear-all-tabs key'',
  37. ;; we mean that you should attach to the letter `a' in function-keymap
  38. ;; whatever command you want to be executed when you type the
  39. ;; clear-all-tabs key on any terminal.  The terminal-dependent
  40. ;; files will attempt to make this work.  If a terminal has no
  41. ;; clear-all-tabs key that can be recognized, it makes no difference
  42. ;; what binding you give to `a' in function-keymap.
  43.  
  44. ;; a -- clear all tabs key
  45. ;; c -- erase key
  46. ;; d -- down-arrow
  47. ;; e -- enter key
  48. ;; f -- find key or search key
  49. ;; h -- home-position key
  50. ;; k -- delete key or remove key.
  51. ;; l -- left-arrow
  52. ;; p -- portrait mode
  53. ;; q -- landscape mode
  54. ;; r -- right-arrow
  55. ;; s -- select key
  56. ;; t -- clear tab this column key
  57. ;; u -- up-arrow
  58. ;; x -- do key
  59. ;; ? -- help
  60.  
  61. ;; - -- keypad key labelled `-'.
  62. ;; . -- keypad key labelled `.'.
  63. ;; , -- keypad key labelled `,'.
  64. ;; 0 ... 9 -- keypad key labelled with that digit,
  65. ;;   but only if that key is not also an arrow key.
  66.  
  67. ;; C-@, C-a, ... C-x -- numbered function keys 0 through 24.
  68. ;; These are used for function keys with no labels but numbers,
  69. ;; and may also be used for function keys with labels
  70. ;; that we have not defined letters for.
  71.  
  72. ;; A -- insert line key
  73. ;; C -- clear screen key
  74. ;; D -- delete character key.
  75. ;; E -- clear to end of line key
  76. ;; F -- scroll forward key
  77. ;; H -- home-down
  78. ;; I -- insert character key
  79. ;;       If there is just an "insert" key, it should be this.
  80. ;; L -- delete line key
  81. ;; M -- exit insert mode key
  82. ;; N -- next page key
  83. ;; P -- previous page key
  84. ;; R -- scroll reverse key
  85. ;; S -- clear to end of screen key
  86. ;; T -- set tab this column key
  87.  
  88. (defun keypad-default (char definition)
  89.   (or (lookup-key function-keymap char)
  90.       (define-key function-keymap char definition)))
  91.  
  92. ;; Here are the standard command meanings we give to the various
  93. ;; function key names.  Because this file is loaded after the user's
  94. ;; init file, we are careful to avoid overriding any definitions
  95. ;; already stored in function-keymap by the init file or (less often)
  96. ;; by the terminal-specific term/*.el file.
  97.  
  98. (keypad-default "l" 'backward-char)
  99. (keypad-default "r" 'forward-char)
  100. (keypad-default "D" 'delete-char)
  101. (keypad-default "u" 'previous-line)
  102. (keypad-default "d" 'next-line)
  103. (keypad-default "N" 'scroll-up)
  104. (keypad-default "P" 'scroll-down)
  105. (keypad-default "C" 'recenter)
  106. (keypad-default "?" 'help-for-help)
  107. (keypad-default "s" 'set-mark-command)
  108. (keypad-default "k" 'kill-region)
  109. (keypad-default "f" 're-search-forward)
  110.  
  111. (keypad-default "\C-a" 'beginning-of-line)
  112. (keypad-default "\C-b" 'end-of-line)
  113. (keypad-default "\C-c" 'isearch-forward)
  114. (keypad-default "\C-d" 'kill-line)
  115.  
  116. (keypad-default "." 'delete-char)
  117. (keypad-default "0" 'yank)
  118. (keypad-default "e" 'open-line)
  119. (keypad-default "1" 'backward-word)
  120. (keypad-default "3" 'forward-word)
  121. (keypad-default "7" 'backward-paragraph)
  122. (keypad-default "9" 'forward-paragraph)
  123. (keypad-default "h" 'move-to-window-line)
  124.  
  125. (defun setup-terminal-keymap (map translations)
  126.   "Set up keymap MAP to forward to function-keymap according to TRANSLATIONS.
  127. TRANSLATIONS is an alist; each element of it looks like (FROMSTRING . TOCHAR).
  128. For each such pair, we define the key sequence FROMSTRING in MAP
  129. to forward to the definition of character TOCHAR in function-keymap.
  130. \"Forwarding\" means that subsequent redefinition of TOCHAR in
  131. function-keymap will be seen automatically in MAP as well.
  132.  
  133. This function is used by files term/*.el to set up the mapping from the
  134. escape sequences sent by function keys on particular terminals (FROMSTRINGs)
  135. into Emacs standard function key slots (TOCHARs).
  136. An actual definition (such as a symbol) may be given in place of TOCHAR.
  137. Generally, MAP is a prefix keymap which will be attached to a key
  138. that is the common prefix sent by all function keys (often ESC O or ESC [)."
  139.   (while translations
  140.     (define-key map (car (car translations))
  141.       (if (numberp (cdr (car translations)))
  142.       (cons function-keymap (cdr (car translations)))
  143.     (cdr (car translations))))
  144.     (setq translations (cdr translations))))
  145.  
  146. (defun function-key-sequence (char)
  147.   "Return key sequence for function key that on this terminal
  148. translates into slot CHAR in function-keymap.
  149. Or return nil if there is none."
  150.   (car (where-is-internal (cons function-keymap char) (current-local-map))))
  151.  
  152. (provide 'keypad)
  153.